﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace NNCore
{
    public class NetXmlSerializer : NetLoader
    {

        FileStream stream;

        private string path;
        private XmlSerializer xmlE;

        public NetXmlSerializer(string path)
        {
            this.path = path;
            xmlE = new XmlSerializer(typeof(NN));
        }

        public NN loadNN()
        {
            XmlSerializer xmlE = new XmlSerializer(typeof(NN));

            try
            {
                stream = new FileStream(path, FileMode.Open);
                return (NN) xmlE.Deserialize(stream);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                stream.Close();
            }
        }


        public void saveNN(NN saveMe)
        {
            try
            {
                stream = new FileStream(path, FileMode.Create);
                xmlE.Serialize(stream, saveMe);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                stream.Close();
            }
        }
    }
}
